﻿resumeApp.factory('resumeService', ['$http', '$log', '$q', function($http, $log, $q) {

    //this uses $resource
    //var resource = $resource('/api/Resume/:id', {id: '@id'});
    //return {
    //    getResumes: function() {
    //        var deferred = $q.defer();
    //        resource.query({},
    //            function(resumes) {
    //                deferred.resolve(resumes);
    //            },
    //            function(resumes) {
    //                deferred.reject(resumes);
    //            });

    //        return deferred.promise;
    //    },
    //    InsertResume: function() {

    //    }

    //};

    //this uses a promise
    var getResumes = function() {
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: '/api/Resume'
        }).success(function(data, status, headers, config) {
            $log.info(data, status, headers(), config);
            deferred.resolve(data);
        }).error(function(data, status, headers, config) {
            $log.warn(data, status, headers(), config);
            deferred.reject(status);
        });
        return deferred.promise;
    };
    var insertResume = function(resume) {
        $http({
            method: 'POST',
            url: '/api/Resume/InsertResume',
            data: resume
        }).success(function(data, status, headers, config) {
            $log.info(data, status, headers(), config);
        });
    };
    
    var updateResume = function(resume) {

    };

    return {
        getResumes: getResumes,
        insertResume: insertResume,
        updateResume: updateResume
    };

}]);